All files / src/components/admin/systemConfiguration schemas.ts

0% Statements 0/10
0% Branches 0/9
0% Functions 0/1
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                                                                               
import { z } from 'zod';
import i18n from '@/lib/i18n';
 
export const creditConfigSchema = z.object({
  default_devices: z.number().min(1).max(10),
  credit_per_user_3_devices: z.number().min(0),
  credit_per_user_5_devices: z.number().min(0),
  credit_per_extra_device: z.number().min(0)});
 
export const tmdbConfigSchema = z
  .object({
    tmdb_api_key: z.string().optional(),
    tmdb_enabled: z.boolean(),
    tmdb_language: z.string().optional(),
    // Use 'online' | 'offline' to match backend config types
    tmdb_mode: z.enum(['online', 'offline']),
    tmdb_metadata_path: z.string().optional(),
    tmdb_preferred_format: z
      .enum(['original', 'webp', 'png', 'jpg'])
      .optional()})
  .superRefine((data, ctx) => {
    // When TMDB is enabled and running in online mode, API key is required
    if (data.tmdb_enabled && data.tmdb_mode === 'online' && !data.tmdb_api_key?.trim()) {
      ctx.addIssue({
        path: ['tmdb_api_key'],
        code: z.ZodIssueCode.custom,
        message: i18n.t('errors.invalidData')});
    }
    // When TMDB is configured to run in offline mode, metadata path is required
    if (data.tmdb_mode === 'offline' && !data.tmdb_metadata_path?.trim()) {
      ctx.addIssue({
        path: ['tmdb_metadata_path'],
        code: z.ZodIssueCode.custom,
        message: i18n.t('errors.invalidData')});
    }
  });
 
export type CreditConfigData = z.infer<typeof creditConfigSchema>;
export type TMDBConfigData = z.infer<typeof tmdbConfigSchema>;